package com.ny.demo529;

import java.util.Map;
import java.util.Collection;

public class TestMap {
    public static void menu() {
        System.out.println("欢迎来到员工信息管理系统(Map版本)");
        System.out.println("0.退出系统");
        System.out.println("1.添加员工");
        System.out.println("2.查询所有的员工");
        System.out.println("3.根据员工姓名查询");
        System.out.println("4.删除员工信息");
        System.out.println("5.根据员工编号查询");
        System.out.println("6.根据员工编号修改年龄");
        System.out.println("请选择你需要进行的操作");
    }

    public void addEmp(Map<String, Emp> map, Emp emp) {
        map.put(emp.getNumber(), emp);
    }

    public void findAllEmp(Map<String, Emp> map) {
        Collection<Emp> emps = map.values();
        for (Emp emp : emps) {
            System.out.println(emp);
        }
    }

    public void findEmpName(Map<String, Emp> map, String name) {
        for (Emp emp : map.values()) {
            if (name.equals(emp.getName())) {
                System.out.println(emp);
            }
        }
    }

    public void deleteEmpNumber(Map<String, Emp> map, String number) {
        if (map.remove(number) != null) {
            System.out.println("员工编号为 " + number + " 的员工已删除");
        } else {
            System.out.println("未找到该员工");
        }
    }

    public Emp findEmpNumber(Map<String, Emp> map, String number) {
        return map.get(number);
    }

    public void updateEmpAge(Map<String, Emp> map, String number, int newAge) {
        Emp emp = map.get(number);
        if (emp != null) {
            emp.setAge(newAge);
            System.out.println("员工年龄已更新");
        } else {
            System.out.println("未找到该员工");
        }
    }
}
